<?php 
session_start();
require_once('include/connect.inc.php');
$now= date("Y-m-d H:i:s");
if($_SESSION['sess_id'] <> session_id()){
?>
 <SCRIPT LANGUAGE="JavaScript">
			alert("กรุณาเข้าสู่ระบบให้ถูกต้องตามขั้นตอน...!");
			location="login.php";
</script>
<?php }?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content="2">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Model Test Program</title>
<link rel="stylesheet" type="text/css" href="template/template_style_wood.css">
<style type="text/css">
<!--
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
-->
</style></head>
<body>
<div id="menu"><div><img src="../images/icon-m.png" /></div>
<div id="menulinks">
		<a  href="person_stu.php">ข้อมูลส่วนตัว</a>
		<a href="stu_edit.php">เปลี่ยนรหัสผ่านใหม่</a>
        <a class="active" href="frm_showset_dotest.php">รายการสอบ</a>
        <a  href="show_dotest_result.php">ผลการสอบ</a>
        <a  href="problem/student_send_problem.php">แสดงความคิดเห็น</a>
        <a  href="problem/student_message.php">กล่องข้อความ</a>
        <a href="logout.php">ออกจากระบบ</a>
</div></div>
    
 <div id="p3">    
<div id="header"></div>
<div id="page"><div id="p1">คุณ<?php echo $_SESSION['student_name'];?> <hr />
<form id="form1" name="form1" method="post" action="">
 	<table border="0"  id="table"  summary="2007 Major IT Companies Profit">
  	<tr>
    	<th align="center">ลำดับ</th>
    	<th align="center">รหัสชุดข้อสอบ</th>
    	<th align="center">รายละเอียด</th>
    	<th align="center">วันเริ่มทำข้อสอบ</th>
    	<th align="center">วันข้อสอบหมดอายุ</th>
    	<th align="center">เวลาทำข้อสอบ</th>
    	<th align="center">ทำข้อสอบ</th>
  	</tr>
<?php
$number=0;
  $query00= query("SELECT * FROM tb_agree where r_student_id='".$_SESSION['id']."' order by set_id desc");
  	while ($rs0= fetch_array($query00)) {// Begin while **1
		$set_ids= $rs0['set_id'];
		
		$query = query("SELECT * FROM tb_set_of_test
		Inner Join  tb_subject ON tb_subject.subject_id = tb_set_of_test.subject_id
		Inner Join  tb_topic ON tb_topic.topic_id = tb_set_of_test.topic_id and set_id='$set_ids' order by set_id desc");
			while ($rs = fetch_array($query)) {// Begin while **2
				$set_id= $rs['set_id'];
				$set_date_cre = $rs['set_date_cre'];
				$start_dates = $rs['start_dates'];
				$end_dates = $rs['end_dates'];
				$end_dates = $rs['end_dates'];
				$set_time_dotest = $rs['set_time_dotest'];
				$topic_detail = $rs ['topic_detail'];
				$subject_name = $rs ['subject_name'];
				$number++;
		?>
  <tr>
    <td align="center"><? echo $number; echo ".";?></td>
    <td align="center"><font size="+1"><strong><? echo "$set_id"?></strong></font></td>
    <td>ข้อสอบวิชา(<? echo "$subject_name";?>) - หัวข้อ  :<? echo "$topic_detail";?></td>
    <td align="center"><? echo "$start_dates"?></td>
    <td align="center"><? echo "$end_dates"?></td>
    <td align="center"><? echo "$set_time_dotest"?>  นาที</td>
    <td align="center">
<?php 
	$now	= date("Y-m-d H:i:s");
	$houreN	= substr($now, 11, 2);
	$times1	= date('Y-m-d H:i:s ',strtotime("now-1 hours"));
?>    
<?php 
		$query0	= query("SELECT * FROM tb_agree where (set_id='$set_id') and (r_student_id='".$_SESSION['id']."')");
		if(num_rows($query0)>0){
			$date	= date("Y-m-d H:i:s");
			$query1	= query("SELECT * FROM tb_set_of_test where ('$date'  BETWEEN '$start_dates' and '$end_dates')");
				if(num_rows($query1)>0){
					$query2= query("SELECT set_id FROM tb_dotest where (set_id='$set_id') and (r_student_id='".$_SESSION['id']."')");
						if(num_rows($query2)>0){
							echo"คุณได้ทำแล้ว!!!";
						}else{
?>
							<a href="exam/frm_student_dotest.php?set_id=<?php echo "$set_id"?>" target="_blank" onClick="return confirm('ยืนยันการเริ่มข้อสอบ!!!  คุณทำชุดนี้ได้ครั้งเดียวนะครับ')"><font size="+2" color="#FF0000"><strong>เริ่มทำ</strong></font></a>
				  <?php }
				 }else{ 
				 	echo "ตรวจสอบวันที่!!!"; } 
				 }else{ 
			echo "ตรวจสอบสิทธิ์!!!";
		}?>
	 </td>
  </tr>
  <?php }// end while **2
}// end whil **1 ?>
</table>
</form>
    </div>
    </div>
<div id="footer"></div>
</div>
</body>
</html>